-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 (api.py): Raise correct error when timeout #45
base: master
Are you sure you want to change the base?
Conversation
eea3c48
to
3c9dece
Compare
3c9dece
to
91ad893
Compare
I think that is not quite correct. I would do it like this: def _call(self, event, data=None) -> Any:
try:
r = self.sio.call(event, data, timeout=self.timeout)
except socketio.exceptions.TimeoutError:
raise Timeout(f"Timed out while waiting for event {event}")
if isinstance(r, dict) and "ok" in r:
if not r["ok"]:
raise UptimeKumaException(r.get("msg"))
r.pop("ok")
return r |
Hum 🤔 , wdym exactly? Because the way I've done it, it will return the correct error if socket.io returns a |
@lucasheld , I ping you, to correct if necessary |
if not r["ok"]: | ||
raise UptimeKumaException(r.get("msg")) | ||
try: | ||
r = self.sio.call(event, data, timeout=self.timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response of self.sio.call
is not always a dict (for example api.need_setup
). In this case r.pop("ok")
fails. You have deleted the code that checks if the response type is a dict.
Also you have deleted the code that checks the r["ok"]
value. The UptimeKumaException is now no longer raised when Uptime Kuma responds with an error message (when r["ok"]
is false).
uptime_kuma_api/api.py
Outdated
except socketio.exceptions.TimeoutError: | ||
raise Timeout(f"Timed out while waiting for event {event}") | ||
except Exception as e: | ||
raise UptimeKumaException(r.get("msg")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r
is not defined when self.sio.call
fails.
I have tested this code. It works as expected. The only problem I noticed is that there are still exceptions directly from socketio (for example |
Alright, I understand and now its fix ! :D |
Related to : #44
I'll let you try it for yourself, and let me know if this function has any dependencies elsewhere.